<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>添加房源</title>
    <link rel="stylesheet" href="/static/common/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/common/css/uploadpic.css">
    <link rel="stylesheet" href="/static/common/css/style.css">
    <link rel="stylesheet" href="/static/common/css/webuploader.css">
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=QIw7CEn9awTfvoOMeBoRfA5X4gHVYIB3"></script>
    <style type="text/css">
        .layui-upload-img {
            width: 92px;
            height: 92px;
            margin: 0 10px 10px 0;
        }

        .site-block {
            width: 95%;
            padding: 20px;
            border: 2px solid #eee;
        }

        .site-text {
            position: relative;
        }

        .title-location {
            font-size: 20px;
            font-weight: 600;
        }

        .rightlayer {
            display: inline-block;
        }

        .layui-form-item {
            width: 100%;
            margin-bottom: 0px;
        }

        .layui-inline {
            display: inline-block;
            width: 49% !important;
        }

        .layui-inline-two {
            float: right;
            margin-right: 0px !important;
        }

        .layui-input:focus, .layui-textarea:focus {
            border-color: red !important;
        }

        .li-img {
            position: absolute;
            right: 0px;
            font-size: 25px;
            font-weight: 700;
            top: 0px;
            color: red;
            background-color: white;
            border: 1px solid lightsteelblue;
            height: 27px;
        }
    </style>
</head>
<body style="margin: 20px 20px ">
<div class="site-text site-block ">
    <form class="layui-form layui-form-pane " lay-filter="layuiForm">
        <div class="layui-form-item">
            <label class="title-location">${officeBuildingName}&nbsp;- &nbsp;编辑房源</label>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">所属区域</label>
                <div class="layui-input-block">
                    <select name="county_id" lay-verify="required" lay-filter="county">
                        <option value="">请选择区域</option>
                    <#list data as d>
                        <option value="${d.county_id}">${d.name}</option>
                    </#list>
                    </select>
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">所属商圈</label>
                <div class="layui-input-block">
                    <select name="trade_area_id" id="tradeArea" lay-filter="tradeArea" lay-verify="required">
                    <#if tradeAreaList?size gt 0>
                        <#list tradeAreaList as data>
                            <option value="${data.county_id}">${data.name}</option>
                        </#list>
                    </#if>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">所属楼盘</label>
                <div class="layui-input-block">
                    <select name="building_id" id="building_id" lay-filter="building_id" lay-verify="required">
                    <#if officeBuildingsList?size gt 0>
                        <#list officeBuildingsList as data>
                            <option value="${data.building_id}">${data.building_name}</option>
                        </#list>
                    </#if>
                    </select>
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">楼层/门牌</label>
                <div class="layui-input-block">
                    <input type="text" name="doorplate" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">建筑面积</label>
                <div class="layui-input-inline" style="width:calc(100% - 150px);">
                    <input type="text" name="coveredArea" lay-verify="required|number" id="date1" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="width: 20px;font-size: 20px">㎡</div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">使用面积</label>
                <div class="layui-input-inline" style="width:calc(100% - 150px);">
                    <input type="text" name="usableArea" lay-verify="required|number" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="width: 20px;font-size: 20px">㎡</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">出租租金</label>
                <div class="layui-input-inline" style="width:calc(100% - 218px);margin-right:0px">
                    <input type="text" name="rentMoney" lay-verify="required" id="date1" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline " style="width: 110px;float: right;margin-right: 0;">
                    <select name="rentUnit" id="rentUnit" lay-filter="building_id" lay-verify="required">
                        <option value="元/m²/月">元/m²/月</option>
                        <option value="元/月">元/月</option>
                        <option value="元/m²">元/m²</option>
                        <option value="元/m²/天">元/m²/天</option>
                        <option value="万元">万元</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">售价金额</label>
                <div class="layui-input-inline" style="width:calc(100% - 218px);margin-right:0px">
                    <input type="text" name="sellMoney" lay-verify="required" autocomplete="off" class="layui-input">
                </div>
                <div class="layui-input-inline" style="width: 110px;float: right;margin-right: 0;">
                    <select name="sellUnit" id="sellUnit" lay-filter="sellUnit" lay-verify="required">
                        <option value="元/m²">元/m²</option>
                        <option value="万元">万元</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">室内装修</label>
                <div class="layui-input-block layui-input-margin" style="border: 1px solid #e6e6e6;min-width: 290px">
                    <input type="radio" name="decorate" value="清水" title="清水" checked>
                    <input type="radio" name="decorate" value="简装" title="简装">
                    <input type="radio" name="decorate" value="精装" title="精装">
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">容纳工位</label>
                <div class="layui-input-block">
                    <input type="text" name="station" lay-verify="required" autocomplete="on" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">办公格局</label>
                <div class="layui-input-block " style="border: 1px solid #e6e6e6;min-width: 290px">
                    <input type="text" lay-verify="required" name="structure" value="" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">朝向</label>
                <div class="layui-input-block">
                    <input type="text" name="orientation" lay-verify="required" autocomplete="on" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">最短租期</label>
                <div class="layui-input-inline" style="width:calc(100% - 166px);">
                    <input type="text" lay-verify="required" name="rentNum" value="面议" autocomplete="on" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="width: 36px;font-size: 18px">个月</div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">免租期</label>
                <div class="layui-input-inline" style="width:calc(100% - 166px);">
                    <input type="text" name="rentFree" lay-verify="required" autocomplete="on" value="面议" class="layui-input">
                </div>
                <div class="layui-form-mid layui-word-aux" style="width: 36px;font-size: 18px">个月</div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">选址顾问</label>
                <div class="layui-input-block " style="border: 1px solid #e6e6e6;min-width: 290px">
                    <input type="text" lay-verify="required" name="contacts" value="小筷" autocomplete="on" class="layui-input">
                </div>
            </div>
            <div class="layui-inline layui-inline-two">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="required" maxlength="11" value="023-63021910" autocomplete="on" class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">其他描述</label>
            <div class="layui-input-block">
                <textarea placeholder="请输入内容(最多1000字)" name="description" class="layui-textarea" maxlength="1000"></textarea>
            </div>
        </div>
        <div class="layui-form-item " pane>
            <label class="layui-form-label" style="height: 180px!important;">楼盘封面图</label>
            <div class="layui-input-block" style="padding:  2px 2px 2px 15px;height: 180px!important;">
                <button type="button" class="layui-btn" id="test1">上传图片</button>
                <div class="layui-input-block">
                    <img class="layui-upload-img" id="demo1" style="margin: 4px -108px;">
                    <p id="demoText" style="margin: 4px -108px;"></p>
                </div>
                <input type="hidden" name="cover_img_path" value="" id="cover_img_path">
            </div>
        </div>
    <#assign text_img=object.context_img_path />
    <#assign data_img=text_img?eval />
        <div class="layui-form-item" pane>
            <label class="layui-form-label">详情图</label>
            <div class="layui-input-block" style="padding: 8px">
            <#list data_img as img>
                <div style="display: inline-block;position: relative;">
                    <i class="li-img layui-icon" onclick="updataImgV(this,'${img.minPath}')">&#x1006;</i>
                    <img src="${img.minPath}" style="height: 120px;width: 80px;border: 1px solid lightsteelblue;">
                </div>
            </#list>
            </div>
        </div>
        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">上传图片</label>
            <div class="layui-input-block">
                <div class="page-container">
                    <div id="uploader" class="wu-example">
                        <div class="queueList">
                            <div id="dndArea" class="placeholder" style="min-height:150px!important;">
                                <div id="filePicker"></div>
                                <p>或将照片拖到这里，单次最多可选20张</p>
                            </div>
                        </div>
                        <div class="statusBar" style="display:none;">
                            <div class="progress">
                                <span class="text">0%</span>
                                <span class="percentage"></span>
                            </div>
                            <div class="info"></div>
                            <div class="btns">
                                <div id="filePicker2"></div>
                                <div class="uploadBtn">开始上传</div>
                            </div>
                        </div>
                    </div>
                </div>
                <input type="hidden" id="uploadPicPath" name="context_img_path" value="">
            </div>
        </div>
        <input type="hidden" name="houes_id" id="houes_id" value="">
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" lay-submit="" lay-filter="formDemo">立即提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
</body>
<script type="text/javascript" src="/static/common/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="/static/common/layui/layui.js"></script>
<script type="text/javascript" src="/static/common/js/webuploader.min.js"></script>
<script type="text/javascript" src="/static/common/js/uploadpic.js"></script>
<script type="text/javascript">
    function updataImgV(_this, path) {
        var imgJson = JSON.parse($("#uploadPicPath").val());
        var imgJsonNew = new Array();
        for (i = 0; i < imgJson.length; i++) {
            if (imgJson[i].minPath == path) {
                $(_this).parent().remove();
            } else {
                imgJsonNew.push(imgJson[i])
            }
        }
        $("#uploadPicPath").val(JSON.stringify(imgJsonNew));
    }
</script>
<script type="text/javascript">
    layui.use('form', function () {
        var form = layui.form;
        //监听提交
        form.on('submit(formDemo)', function (data) {
            console.log(data.field);
            var cover_img_path = $("#cover_img_path").val();
            if (cover_img_path == null || cover_img_path == '' || cover_img_path == undefined) {
                layer.alert("还没有上传封面图!");
                return false;
            }
            var context_img_path = $("input[name='context_img_path']").val();
            if (context_img_path == null || context_img_path == '' || context_img_path == undefined) {
                layer.alert("还没有上传图!");
                return false;
            }
            $.post('/officeBuilding/house/update.do', data.field, function (res) {
                if (res.data == 'SUCCESS') {
                    layer.confirm('更新成功!是否要房源列表?', {icon: 1, title: '提示'}, function (index) {
                            window.location.href='/officeBuilding/house/list.do';
                    });
                } else {
                    layer.alert('更新失败!', {icon: 2});
                }
            })
            return false;
        });
        /**************************insulate**********************************/
        //区域选址
        form.on('select(county)', function (data) {
            $.post("/officeBuilding/building/ajaxTradeArea.do", {id: data.value}, function (result, status) {
                $("#tradeArea").html('');
                $("#building_id").html('');
                for (i = 0; i < result.data.length; i++) {
                    $("#tradeArea").append('<option value="' + result.data[i].county_id + '">' + result.data[i].name + '</option>')
                }
                form.render('select');
            }, "json");
        });
        /**************************insulate**********************************/

        form.val("layuiForm",${houseJson})
        /**************************insulate**********************************/
        //楼盘
        form.on('select(tradeArea)', function (data) {
            $.post("/officeBuilding/house/ajxaBuilding.do", {trade_area_id: data.value}, function (result, status) {
                $("#building_id").html('');
                for (i = 0; i < result.data.length; i++) {
                    $("#building_id").append('<option value="' + result.data[i].building_id + '">' + result.data[i].building_name + '</option>')
                }
                form.render('select');
            }, "json");
        });
        /**************************insulate**********************************/
        var imgPath = $('#cover_img_path').val();
        imgPath = JSON.parse(imgPath);
        $('.layui-upload-img').attr('src', imgPath.minPath);

        var imgCPath = $('#uploadPicPath').val();
        imgPath = JSON.parse(imgCPath);
        /**************************insulate**********************************/
    });
    layui.use('upload', function () {
        var $ = layui.jquery
                , upload = layui.upload;
        //普通图片上传
        var uploadInst = upload.render({
            elem: '#test1',
            url: '/officeBuilding/building/upload.do',
            exts: 'jpg|jpeg',
            before: function (obj) {
                layer.msg('上传中...', {icon: 16, shade: 0.01});
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#demo1').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                //如果上传失败
                if (res.success == false) {
                    layer.closeAll('loading');
                    return layer.alert('上传失败');
                } else { //上传成功
                    var demoText = $('#demoText');
                    demoText.html('<span style="color: #01b84e;">上传成功</span>');
                    $("#cover_img_path").val(JSON.stringify(res.data));
                    layer.closeAll('loading');
                    return layer.alert('上传成功');
                }
            }
            , error: function () {
                //演示失败状态，并实现重传
                var demoText = $('#demoText');
                demoText.html('<span style="color: #FF5722;">上传失败</span> <a class="layui-btn layui-btn-mini demo-reload">重试</a>');
                demoText.find('.demo-reload').on('click', function () {
                    uploadInst.upload();
                });
            }
        });
    })

</script>
<script src="/static/common/js/ajaxhook.js" type="text/javascript"></script>
<script src="/static/common/js/ajaxHookData.js" type="text/javascript"></script>
</html>